export {}
//接口interface 约束对象的结构

interface Post{
 title:string
 content?:string //可选成员
 readonly summary:string
}
function printPost (post:Post){
    return post.title
}
const obj:Post={
    title:'11',
    summary:'a ts'
}
// obj.summary='666' 会报错

interface Cache{
  [key:string]:string
}
const cache :Cache={}
cache.name='666'

// 类  描述一个事物的具体类型特征

class  Person{
    public name:string  //默认就是public 建议写
    private age:number //只能在类的内部访问
    protected sex:string='nan' //只允许在子类中访问
    constructor(name:string,age:number,sex?:string){
      this.name =name
      this.age=age
      this.sex=sex as string
    }
    sayHi(msg:string){
        console.log(msg + this.name)
    }
    
}
interface Eat{
    eat(food:string):void
}
interface Run{
    run(run:string):void
}
class  Student extends Person implements Eat ,Run{
  public  readonly num  //只读属性
  private constructor(name:string,age:number,num:number){
      super(name,age)
      this.num =num
      console.log(this.sex)
  }
  static create(name:string,age:number,num:number){
      return new Student(name,age,num)
  }
  eat(food:string):void{
    console.log('enenen')
  }
  run(run:string):void{
    console.log('ppp')
  }
}
let  s = Student.create('caozy',18,55555)
// s.num='6666'//会报错

//类与接口

abstract class Animal implements Eat{
    eat(food:string):void{
        console.log('aoaoao')
    }
    abstract run(dis:string):void
}
class Dog extends Animal{
    run(dis:string):void{
        console.log(dis)
    }
}
//抽象类abstract只能被继承不能被实例化

//泛型  把不能明确的类型当错参数
function  createArray<T>(len:number,value:T):T[]{
    const arr = Array<T>(len).fill(value)
    return arr
}
//类型声明  解决三方库函数没有声明的问题
declare function name (params:string):void 